package com.shilan.administrator.qintfm.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.shilan.administrator.qintfm.R;
import com.shilan.administrator.qintfm.beans.SleepTime;

import de.greenrobot.event.EventBus;

/**
 * Created by dllo on 16/1/25.
 */
public class TimeSettingFragment extends BaseFragment implements View.OnClickListener {

    private RadioGroup radioGroup;
    private RadioButton radioButton01,radioButton02,radioButton03,radioButton04,
            radioButton05,radioButton06;
    private ImageView imageView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_time_setting,null);
        imageView = (ImageView) view.findViewById(R.id.btn_timesetting_back);
        imageView.setOnClickListener(this);

        radioGroup = (RadioGroup) view.findViewById(R.id.fragment_radiogroup);
//        radioButton01 = (RadioButton) view.findViewById(R.id.rb_nosetting);
//        radioButton02 = (RadioButton) view.findViewById(R.id.rb_ten_min);
//        radioButton03= (RadioButton) view.findViewById(R.id.rb_twe_min);
//        radioButton04 = (RadioButton) view.findViewById(R.id.rb_thirty_min);
//        radioButton05= (RadioButton) view.findViewById(R.id.rb_one_hour);
//        radioButton06= (RadioButton) view.findViewById(R.id.rb_ninety_min);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
//                if (checkedId == R.id.rb_nosetting){
//                    EventBus.getDefault().post();
//                }else
                if (checkedId==R.id.rb_ten_min){
                    EventBus.getDefault().post(new SleepTime(1000*60*10));
                    Toast.makeText(getActivity(), "10分钟后将停止播放歌曲", Toast.LENGTH_SHORT).show();
                }else
                if (checkedId==R.id.rb_twe_min){
                    EventBus.getDefault().post(new SleepTime(1000*60*20));
                    Toast.makeText(getActivity(), "20分钟后将停止播放歌曲", Toast.LENGTH_SHORT).show();
                }else
                if(checkedId==R.id.rb_thirty_min){
                    EventBus.getDefault().post(new SleepTime(1000*60*30));
                    Toast.makeText(getActivity(), "30分钟后将停止播放歌曲", Toast.LENGTH_SHORT).show();
                }else
                if (checkedId==R.id.rb_one_hour){
                    EventBus.getDefault().post(new SleepTime(1000*60*60));
                    Toast.makeText(getActivity(), "60分钟后将停止播放歌曲", Toast.LENGTH_SHORT).show();
                }else
                if (checkedId==R.id.rb_ninety_min){
                    EventBus.getDefault().post(new SleepTime(1000*60*90));
                    Toast.makeText(getActivity(), "90分钟后将停止播放歌曲", Toast.LENGTH_SHORT).show();
                }
            }
        });

        return view;

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_timesetting_back:
                goBack();
                break;
        }
    }
}
